package com.mall.module.system.controller;

import com.github.pagehelper.PageInfo;
import com.mall.common.result.Result;
import com.mall.module.system.domain.entity.SysDict;
import com.mall.module.system.service.SysDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统字典控制器
 */
@Api(tags = "系统字典接口")
@RestController
@RequestMapping("/api/system/dict")
public class SysDictController {
    
    @Autowired
    private SysDictService dictService;
    
    /**
     * 获取字典列表
     */
    @ApiOperation(value = "获取字典列表")
    @GetMapping("/list")
    public Result<PageInfo<SysDict>> list(
            @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页记录数", defaultValue = "10") @RequestParam(defaultValue = "10") Integer pageSize,
            @ApiParam(value = "字典类型") @RequestParam(required = false) String dictType,
            @ApiParam(value = "字典键") @RequestParam(required = false) String dictKey,
            @ApiParam(value = "状态") @RequestParam(required = false) Integer status) {
        PageInfo<SysDict> pageInfo = dictService.listDictPage(pageNum, pageSize, dictType, dictKey, status);
        return Result.success(pageInfo);
    }
    
    /**
     * 根据字典类型获取字典列表
     */
    @ApiOperation(value = "根据字典类型获取字典列表")
    @GetMapping("/type/{dictType}")
    public Result<List<SysDict>> getDictByType(
            @ApiParam(value = "字典类型", required = true) @PathVariable String dictType) {
        List<SysDict> dicts = dictService.listDictByType(dictType);
        return Result.success(dicts);
    }
    
    /**
     * 获取字典详情
     */
    @ApiOperation(value = "获取字典详情")
    @GetMapping("/{id}")
    public Result<SysDict> getInfo(@ApiParam(value = "字典ID", required = true) @PathVariable Long id) {
        SysDict dict = dictService.getDictById(id);
        return Result.success(dict);
    }
    
    /**
     * 根据字典类型和字典键获取字典
     */
    @ApiOperation(value = "根据字典类型和字典键获取字典")
    @GetMapping("/type/{dictType}/key/{dictKey}")
    public Result<SysDict> getDictByTypeAndKey(
            @ApiParam(value = "字典类型", required = true) @PathVariable String dictType,
            @ApiParam(value = "字典键", required = true) @PathVariable String dictKey) {
        SysDict dict = dictService.getDictByTypeAndKey(dictType, dictKey);
        return Result.success(dict);
    }
    
    /**
     * 新增字典
     */
//    @ApiOperation(value = "新增字典")
//    @PostMapping
//    public Result<Void> add(@ApiParam(value = "字典信息", required = true) @RequestBody SysDict dict) {
//        boolean result = dictService.addDict(dict);
//        return result ? Result.success() : Result.failed("新增字典失败");
//    }
//
//    /**
//     * 修改字典
//     */
//    @ApiOperation(value = "修改字典")
//    @PutMapping
//    public Result<Void> update(@ApiParam(value = "字典信息", required = true) @RequestBody SysDict dict) {
//        boolean result = dictService.updateDict(dict);
//        return result ? Result.success() : Result.failed("修改字典失败");
//    }
//
//    /**
//     * 删除字典
//     */
//    @ApiOperation(value = "删除字典")
//    @DeleteMapping("/{id}")
//    public Result<Void> delete(@ApiParam(value = "字典ID", required = true) @PathVariable Long id) {
//        boolean result = dictService.deleteDict(id);
//        return result ? Result.success() : Result.failed("删除字典失败");
//    }
//
//    /**
//     * 批量删除字典
//     */
//    @ApiOperation(value = "批量删除字典")
//    @DeleteMapping("/batch")
//    public Result<Void> batchDelete(@ApiParam(value = "字典ID数组", required = true) @RequestBody List<Long> ids) {
//        boolean result = dictService.deleteDictByIds(ids);
//        return result ? Result.success() : Result.failed("批量删除字典失败");
//    }
} 